<?php
    require_once "../../config.php";
    require_once "../../functions.php";
    //后台
    //接收ajax发来的请求:邮箱和密码
    $email = $_POST["email"];
    $password = $_POST["password"];
    //查询数据库 判断是否有这个用户输入的邮箱和密码
        //连接数据库
        $connect = connect();
        //sql语句
        $sql = "SELECT * from users where email='{$email}' and `PASSWORD`='{$password}' and status ='activated'";
        //执行SQL语句,返回一个二维数组
        $queryResult = querySelect($connect,$sql);
        // print_r($queryResult);
        //如果没有 返回失败
        $response = ["code"=>0,"msg"=>"登录失败"];
        //判断如果有结果
         //如果有,则登录成功
         //说明登录成功
        if($queryResult){
            //记录session的登录状态
            session_start();//开启session
            $_SESSION["isLogin"] = 1;//记录当isLogin=1时,说明该用户已经登录过了
            $_SESSION["user_id"] = $queryResult[0]["id"];
            $response["code"] = 1;
            $response["msg"] = "登陆成功!";
        }
        //成功,将数据返回前端,并且告诉前端这是json数据
        header("content-type:application/json;charset=utf8");
        //以json格式返回
        echo json_encode($response);
   
    
    // echo 1;
?>